//
//  RJOutIntroduction.m
//  AirQuality
//
//  Created by Po on 15/5/20.
//  Copyright (c) 2015年 Po. All rights reserved.
//

#import "RJOutIntroduction.h"

@interface RJOutIntroduction ()
@property (weak, nonatomic) IBOutlet UIScrollView *sectionView;         //标签栏
@property (weak, nonatomic) IBOutlet UIWebView *webView;                //网页
@property (weak, nonatomic) IBOutlet UIButton *returnButton;            //返回按钮

@property (retain, nonatomic) NSString * currentType;                   //当前展示类型
@property (retain, nonatomic) UIButton * currentButton;                 //当前选中的类型
@property (weak, nonatomic) IBOutlet UIButton *aqiButton;

@end

@implementation RJOutIntroduction

- (void)viewDidLoad {
    [super viewDidLoad];
    [_sectionView setContentSize:CGSizeMake(600, 44)];
    _currentType = @"AQI";
    _currentButton = _aqiButton;
    [_aqiButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self updateType:_currentType];
}

#pragma mark - event
- (IBAction)pressReturnButton:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (IBAction)pressSectionButton:(UIButton *)sender {
    [_currentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _currentButton = sender;
    [_currentButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self updateType:sender.titleLabel.text];
}

#pragma mark - function
- (void)updateType:(NSString *)type
{
    _currentType = type;
    NSArray * typeArray = @[@"AQI",@"PM2.5",@"PM10",@"SO2",@"NO2",@"CO",@"O3"];
    NSArray * urlArray = @[
                           @"http://baike.baidu.com/link?url=rR1h9kD26Ejpjd4tgyKQbqk_XELlxmDEE_UeUSKY2T3Kq4k06R61bJiKGtxrZ2ORXStHvOuL9h4vxj6raUyD7aOlEk9kLNVrtVKFlSMzXrG4V35UIm3bkYFQLZFk-jg47eaEhBohs0BAoOr2f-DdZq",
                           @"http://baike.baidu.com/link?url=dGtpYq2Xlgo_ttlS5fz3SgERQ9vYSAbEgE1-vz8bOgrCtAAb87yVWPiLnxnAFdG1o7XLToZUoA5jw7ZUWjIBfyXayop11k8dAacmlMP2KsIvndXUjAbXEeXt-9sNvdmZ63sAbfSghdUVfGbZpItuLK",
                           @"http://baike.baidu.com/link?url=-b33UpnwpLDBlKIb13tYgpyKldVnxZ3X3QEWb1OsCykI4ZmQbRgDb6dUexgO6XfGg3hK5QVP_Ml_U8MrirzRhaMcMEEmhCe_YkyNDTN7hC4gW2Barg0Tq5yJrgiKqzg1CGZ4VFPMMNo8GQMEQkCLea",
                           @"http://baike.baidu.com/link?url=hqK_v-eD44EX06xghi_sF9GLYXU1Pj51MegYTQIFIA5LqfJXCKunsx-gkVF2_DtW8hSJ8wfETsKoqZlXXQq48Dgqvu2VCXdD8dOVqno83TOu7V4PkzoK-Nya4MoQZPWN",
                           @"http://baike.baidu.com/link?url=TCLj_5ILc9fJl0Gp6gZ1BWw7arADkQEUq44mCyPrc8OjwjlMdK8qC4hk1s9vxvffL3LqPCP9Oc9kDSYiySuW0SwxnSUMHxBxjSj31WL7j1asQqOwsJSGJulCbgDxRiZe",
                           @"http://baike.baidu.com/link?url=kYIE2-Vy8uHP7cCUJ4mfliW4-Z_7P_bIV1wTIgImmQLCFkAaW7UW1ltU5ZTXkBJ_zLBYQw96aRIHz6Vv0FOXMa",
                           @"http://baike.baidu.com/view/18827.htm?fr=aladdin&fromtitle=O3&fromid=9533644&type=syn"];
    
    NSUInteger count = [typeArray indexOfObject:type];
    [_webView loadHTMLString: @"" baseURL: nil];
    [_webView loadRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlArray[count]]]];
}
@end
